package com.yxq.mdt.app.modules.video.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.hyphenate.chat.EMClient;
import com.hyphenate.exceptions.EMServiceNotReadyException;
import com.yxq.mdt.app.R;
import com.yxq.mdt.app.base.BaseActivity;
import com.yxq.mdt.app.constant.Constant;
import com.yxq.mdt.app.glide.GlideHelper;
import com.yxq.mdt.app.modules.socialcontact.ui.activity.VideoInviteChatActivity;

import butterknife.BindView;
import butterknife.OnClick;
import cn.jzvd.Jzvd;
import cn.jzvd.JzvdStd;

/**
 * 形象展示视频
 */
public class DisplayVideoAc extends BaseActivity {
    @BindView(R.id.display_me_img)
    ImageView displayMeImg;
    @BindView(R.id.display_name)
    TextView displayName;
    @BindView(R.id.display_home_sex)
    ImageView displayHomeSex;
    @BindView(R.id.display_home_address)
    TextView displayHomeAddress;
    @BindView(R.id.display_home_age)
    TextView displayHomeAge;
    @BindView(R.id.look_me)
    LinearLayout lookMe;
    @BindView(R.id.social_give_present_new)
    TextView socialGivePresentNew;
    @BindView(R.id.social_give_present_new_lint)
    LinearLayout socialGivePresentNewLint;
    @BindView(R.id.item_social_video_player)
    JzvdStd itemSocialVideoPlayer;
    @BindView(R.id.exit)
    ImageView exit;
    private String userName;

    @Override
    public int getLayoutId() {
        setStatusBarDarkFont(false);
        setEnableImmersion(true);
        setStatusBarColor(R.color.black);
        return R.layout.activity_display_video;
    }

    @Override
    public void initView() {
        if (getIntent().getStringExtra("residence") != null) {
            displayHomeAddress.setText(getIntent().getStringExtra("residence"));
        }
        ImageView imageViewVideo = itemSocialVideoPlayer.thumbImageView;
        imageViewVideo.setScaleType(ImageView.ScaleType.CENTER_CROP);
        GlideHelper.setLoadRoundImage(mActivity, getIntent().getStringExtra("video"), 0, imageViewVideo);
        itemSocialVideoPlayer.setUp(getIntent().getStringExtra("video"), "", Jzvd.SCREEN_NORMAL);
        Jzvd.setVideoImageDisplayType(JzvdStd.VIDEO_IMAGE_DISPLAY_TYPE_FILL_SCROP);
        GlideHelper.setLoadRoundImage(mActivity, getIntent().getStringExtra("headimg"), 0, displayMeImg);
        displayName.setText(getIntent().getStringExtra("name"));
        if (getIntent().getStringExtra("age") != null) {
            displayHomeAge.setText(getIntent().getStringExtra("age") + "岁");
        }
        if (getIntent().getStringExtra("sex").equals("1")) {
            displayHomeSex.setImageResource(R.mipmap.xb_nan);
        } else if (getIntent().getStringExtra("sex").equals("2")) {
            displayHomeSex.setImageResource(R.mipmap.xb_nv);
        } else {
            displayHomeSex.setImageDrawable(null);
        }
        userName = "yxq" + getIntent().getStringExtra("userId");
        if (String.valueOf(Constant.getLoginUser().getUserId()).equals(getIntent().getStringExtra("userId"))) {
            socialGivePresentNewLint.setVisibility(View.GONE);
        }
        exit.setOnClickListener(view -> finish());
        socialGivePresentNew.setText(getIntent().getStringExtra("money"));
        itemSocialVideoPlayer.startVideo();
    }

    @Override
    public void initData(@Nullable Bundle savedInstanceState) {

    }


    @OnClick(R.id.social_give_present_new_lint)
    public void onViewClicked() {
        //视频
        //跳转视频聊天界面
        Intent goToChat = new Intent(mActivity, VideoInviteChatActivity.class);
        goToChat.putExtra("userId", userName);
        goToChat.putExtra("nickname", displayName.getText().toString());
        startActivity(goToChat);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case android.R.id.home:
                finish();
                break;
        }
        return super.onOptionsItemSelected(item);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        Jzvd.releaseAllVideos();
    }
}
